package view;

import dao.BookDao;
import model.Book;
import model.User;

import java.util.*;

public class UI {
    /**
     * 用户选择角色
     *
     * @return
     */
    public static int role() {
        Scanner scanner = new Scanner(System.in);
        int role = 1;// 1 用户 2 管理员
        System.out.println("------------------------------------------");
        System.out.println("输入数字选择下列选项对应功能");
        System.out.println("1. 用户登录");
        System.out.println("2. 管理员登录");
//        System.out.println("3. 用户注册");
//        System.out.println("4. 管理员注册");

        System.out.println("------------------------------------------");
        role = scanner.nextInt();
        return role;
    }

    /**
     * 输入账号密码
     */
    public static User login() {
        User user = new User();
        Scanner scanner = new Scanner(System.in);
        System.out.println("------------------------------------------");
        System.out.println("请输入你的账户:");
        System.out.println("------------------------------------------");
        user.setUserName(scanner.next());
        System.out.println("------------------------------------------");
        System.out.println("请输入你的密码:");
        System.out.println("------------------------------------------");
        user.setPassword(scanner.next());
//        System.out.println("------------------------------------------");
        return user;
    }

    public static User userRegister() {
        User user = new User();
        Scanner scanner = new Scanner(System.in);
        System.out.println("------------------------------------------");
        System.out.println("请输入你注册的账户名:");
        System.out.println("------------------------------------------");
        user.setUserName(scanner.next());
        System.out.println("------------------------------------------");
        System.out.println("请输入你注册的密码:");
        System.out.println("------------------------------------------");
        user.setPassword(scanner.next());
        System.out.println("------------------------------------------");
        System.out.println("请输入你的手机号:");
        System.out.println("------------------------------------------");
        user.setPhone(scanner.next());
        System.out.println("------------------------------------------");
        System.out.println("请输入你的性别:");
        System.out.println("------------------------------------------");
        user.setPhone(scanner.next());
        System.out.println("------------------------------------------");
        System.out.println("请输入Y确认注册信息,输入N返回登录页面");
        System.out.println("------------------------------------------");
        String res = scanner.next();
        if (res.equals("Y")) {
            return user;
        } else {
            return null;
        }
    }

    public static int book_list() {
        int selectInt = 0;
        Scanner scanner = new Scanner(System.in);
        System.out.println("--------------------------------");
        System.out.println("书籍列表");
        BookDao bookDao = new BookDao();
        showBookList(bookDao.list());
        System.out.println("--------------------------------------");
        System.out.println("请在一下选项中选择你的操作");
        System.out.println("1. 搜索书籍");
        System.out.println("2. 借书");
        System.out.println("3. 还书");
        System.out.println("4. 退出");
        while (selectInt == 0) {
            int in = scanner.nextInt();
            if (in == 1) {
                System.out.println("请输入你要搜索的书籍名称");
                String bookName = scanner.next();
                showBookList(bookDao.search(bookName));
                selectInt = in;
            }
            if (in == 2) {
                System.out.println("请输入你要借的书籍编号");

                int bookId = scanner.nextInt();
            }
            if (in == 4) {

            }
        }
        return selectInt;
    }

    private static void showBookList(HashSet books) {
        Iterator iterator = books.iterator();
        while (iterator.hasNext()) {
            Book book = (Book) iterator.next();
            book.print();
        }
    }
}
